-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Record embed and const field syntax #474
Conversation
Teal Playground URL: https://474--teal-playground.netlify.app |
Hi @pigpigyyy, thank you for taking the time to make a PR! The code itself looks good, but I'm uncertain about adding these features to the language. These are the reasons:
I'd like to hear what you and other users think about these concerns! |
In most languages there are also ways to get around fields being public, private and/or protected. Yet those languages don't give that idea up and properly setting the access for fields is encouraged instead of having everything be public. Also, by that same logic, the entire type system gives a false sense of security as a simple I think it is best to treat |
I'm using Teal in a C++ project with Lua embedded, and get a lot of native OOP stuff exported into Lua. So I just seek for a way to do the simulated OOP check. Since C++ does not support covariant/contravariant features by default, I'm not worrying too much for it. As for nominal records, I just changed the way to compare records with embeds in order to make subtypes to be not equal. |
@lenscas What I meant by aliasing is different from an explicit |
Thanks @pigpigyyy, I'll give it another review! |
Ah, yes then I fully agree to wait until that to see if |
@hishamhm Did you get a chance to look into this a bit more? I'm personally loving the "embed" design and implementation here. It's feels almost like intersection types from TypeScript. I'm not worried about type-soundness, but being able to express another much-common usage of tables in the type system. // ETA: Some idle discussion about syntax aside. Not directly related to the PR. BIG changes proposed as thought experiments //
Not sure if syntax discussions are closed for good or not, but these are some thoughts coming from TypeScript (specifically using it to compile Lua) pov. HTH. // ETA 2 (Can you tell I'm passionate about this? 😄) Some more realistic (but probably not enough) syntax ideas around types. //
// ETA 3 -- Updated opinions after exploring the ecosystem // While I still like the syntax I suggested in previous edits, I think it would be unrealistic since there seems to be a big enough userbase to break. Not sure if they're implementable without breaking existing code so I'm changing my thinking on this. I think the syntax implemented in this PR seems fine. I now recommend that
If @hishamhm accepts this, I'd be happy to the a full review of this PR, and or update it if @pigpigyyy is not interested in this anymore. Thanks. |
@muratg Thanks for the feedback! Regarding this feature proposal, I think the direction Teal should go is to adopt real intersection types. Various features in the language already hint in this direction (arrayrecords, polymorphic function members in records) so it would be cleaner to replace them with intersection types. I'm sure that intersections would end up having some limitations similar to those we currently have with unions, but I think overall it would make the design cleaner (and the language hopefully smaller, which is not a hard goal but always a hint of elegance). Regarding the other syntax changes, yeah, no intention on changing them now. (Side comment: it's always interesting to see people's different perceptions... most of your suggestions lean towards making it look more like Typescript or Go, which is probably what you're most used to! "Intuitive" is always relative to the beholder — Teal's syntax style follows on the Lua tradition, which is in itself more aligned to the Pascal/Modula family than that of curly-bracket-style languages). |
I agree familiarity is important in deciding what's intuitive. My main issue with colon in map and function syntax was more about But I can totally see your point of view too. It makes sense to target existing Lua users for Teal instead of other languages. Looking forward to seeing the intersection types! I think it should have less limitations compared to union types since it's an extension process and not a contraction. If you already thought of its syntax, please share! |
I'm closing this PR since we'll be getting functionality to address similar use-cases via the Interfaces still need some work (generics, ensuring the subtyping relations all work as intended (tests!!!!)) but I'm pretty happy with the implementation to the point that I've already ported the compiler's own type objects to use them :) |
Just started testing the Next Teal! Everything is supposed to be there except the "readonly field" feature, I will try making a new PR with the newest version. Thanks for your effort! |
Implement the "embed" and "const / readonly" field functions for OOP simulations to support some Lua project uses. The "embed" function is refactored from @euclidianAce's implementation ( mentioned in issue #97 ) with bug fixes.